package be.mapitall;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;



public class MapItAllActivity extends Activity {
	
	private static final int REQUEST_FILE_OPEN = 1;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        Button createButton = (Button) findViewById(R.id.btnMapFromFile);
        createButton.setOnClickListener(new OnClickListener() {
            public void onClick(View view) {
                Intent myIntent = new Intent(view.getContext(), FileDialog.class);
                myIntent.putExtra(FileDialog.SELECTION_MODE, SelectionMode.MODE_OPEN);
                myIntent.putExtra(FileDialog.START_PATH, "/sdcard");
                startActivityForResult(myIntent, REQUEST_FILE_OPEN);
            }
        });
    }
    
    public synchronized void onActivityResult(final int requestCode, int resultCode, final Intent data) {

            if (resultCode == Activity.RESULT_OK) 
            {

                if (requestCode == REQUEST_FILE_OPEN) 
                {
                	String mapfilepath = data.getStringExtra(FileDialog.RESULT_PATH);
                    Intent myIntent = new Intent(this, MapViewActivity.class);
                    myIntent.putExtra(MapViewActivity.MAP_FILE_PATH, mapfilepath);
                    startActivityForResult(myIntent, 0);
                }
					
            }
            else if (resultCode == Activity.RESULT_CANCELED) 
            {
            	System.out.println("File not selected");   
            }

    }
}